*************************************************************************************
*****			Please cite Georgiadou et al. (2018) as indicated in 			*****
*****  	https://www.sciencedirect.com/science/article/pii/S026137941830026X		*****
*************************************************************************************


use Data/GRR_data.dta, clear
cd Graphs
*generate differences to obtain fitted values
carryforward D_par, gen(D_par_carry)
carryforward PRR, gen(PRR_carry)
carryforward ER, gen(ER_carry)
carryforward PRR2, gen(PRR_carry2)
carryforward ER2, gen(ER_carry2)

sort nuts_2 year
gen DPRR=PRR-L.PRR_carry
gen DLunemp= D.Lunemp
gen DLdiff_immigration= D.Ldiff_immigration
gen DLgdp_pps_hab= D.Lgdp_pps_hab
gen DLtax= D.Ltax
gen DLgini= D.Lgini
gen DLwage_sh= D.Lwage_sh
gen DLD_gdp_growth= D.LD_gdp_growth
gen DD_par= D.D_par_carry
gen DLimmigration_cr= D.Limmigration_cr
gen DLunemp_diffimmigration= D.Lunemp_diffimmigration
gen DLunemp_immigr_cr= D.Lunemp_immigr_cr
gen DLgini_disp_inc= D.Lgini_disp_inc
gen DLgini_disp_east= D.Lgini_disp_east

***** Figure A1
** Honoré
qui: pantob PRR Lunemp Ldiff_immigration  Lgdp_pps_hab Ltax Lgini Lwage_sh LD_gdp_growth  D_par nuts_2 
gen DPRR_hat_t1c1= _b[Lunemp]*DLunemp + _b[Ldiff_immigration]*DLdiff_immigration + _b[Lgdp_pps_hab]*DLgdp_pps_hab + _b[Ltax]*DLtax + _b[Lgini]*DLgini + _b[Lwage_sh]*DLwage_sh + _b[LD_gdp_growth]*DLD_gdp_growth + _b[D_par]*DD_par 
gen PRR_hat_t1c1 = L.PRR_carry + DPRR_hat_t1c1
gen PRR_resid_t1c1=PRR-PRR_hat_t1c1
twoway (scatter PRR_resid_t1c1 PRR_hat_t1c1, msize(vsmall)) , yline(0) graphregion(color(white)) ytitle("Residuals") xtitle("Fitted PRR vote") title("Panel-tobit (Honoré 1992)") legend(off) saving(figureA1a,replace)
twoway (scatter PRR PRR_hat_t1c1, msize(vsmall)) (lfit PRR PRR_hat_t1c1 if PRR_hat_t1c1>0),graphregion(color(white)) ytitle("Actual PRR vote") xtitle("Fitted PRR vote") title("Panel-tobit (Honoré 1992)") legend(off) saving(figureA1b,replace)
**Tobit-Dummies
qui: tobit PRR Lunemp Ldiff_immigration   Lgdp_pps_hab Ltax Lgini  Lwage_sh LD_gdp_growth    D_par  i.nuts_2,ll(0)
predict PRR_hat_tA29c2, xb
gen PRR_resid_tA29c2=PRR-PRR_hat_tA29c2
twoway (scatter PRR_resid_tA29c2 PRR_hat_tA29c2, msize(vsmall)) , yline(0) graphregion(color(white)) ytitle("Residuals") xtitle("Fitted PRR vote") title("Tobit - Regional dummies") legend(off) saving(figureA1c,replace)
twoway (scatter PRR PRR_hat_tA29c2, msize(vsmall)) (lfit PRR PRR_hat_tA29c2 if PRR_hat_tA29c2>0),graphregion(color(white)) ytitle("Actual PRR vote") xtitle("Fitted PRR vote") title("Tobit - Regional dummies") legend(off) saving(figureA1d,replace)
*** Tobit random effects
qui: xttobit PRR Lunemp Ldiff_immigration   Lgdp_pps_hab Ltax Lgini  Lwage_sh LD_gdp_growth    D_par,ll(0)
predict PRR_hat_tA29c3, xb
gen PRR_resid_tA29c3=PRR-PRR_hat_tA29c3
twoway (scatter PRR_resid_tA29c3 PRR_hat_tA29c3, msize(vsmall)) , yline(0) graphregion(color(white)) ytitle("Residuals") xtitle("Fitted PRR vote") title("Panel-tobit (Honoré 1992)") legend(off) saving(figureA1e,replace)
twoway (scatter PRR PRR_hat_tA29c3, msize(vsmall)) (lfit PRR PRR_hat_tA29c3 if PRR_hat_tA29c3>0,est(noconstant)),graphregion(color(white)) ytitle("Actual PRR vote") xtitle("Fitted PRR vote") title("Panel-tobit (Honoré 1992)") legend(off) saving(figureA1f,replace)
****Combined graph
gr combine figureA1a.gph figureA1b.gph figureA1c.gph figureA1d.gph figureA1e.gph figureA1f.gph, graphregion(color(white)) rows(3) ysize(10) xsize(8)
graph save ../Graphs/FigureA1.gph, replace
graph export ../Graphs/FigureA1.pdf, replace

cd ..



*** Figure A2
cd Graphs
set more off
*** Honoré 
pantob ER Lunemp Ldiff_immigration   Lgdp_pps_hab Ltax Lgini  Lwage_sh LD_gdp_growth    D_par  nuts_2 
gen DER_hat_tA29c4= _b[Lunemp]*DLunemp + _b[Ldiff_immigration]*DLdiff_immigration + _b[Lgdp_pps_hab]*DLgdp_pps_hab + _b[Ltax]*DLtax + _b[Lgini]*DLgini + _b[Lwage_sh]*DLwage_sh + _b[LD_gdp_growth]*DLD_gdp_growth + _b[D_par]*DD_par 
gen ER_hat_tA29c4 = L.ER_carry + DER_hat_tA29c4
gen ER_resid_tA29c4=ER-ER_hat_tA29c4
twoway (scatter ER_resid_tA29c4 ER_hat_tA29c4 , msize(vsmall)) , yline(0) graphregion(color(white)) ytitle("Residuals") xtitle("Fitted ER vote") title("Panel-tobit (Honoré 1992)") legend(off) saving(figureA2a,replace)
twoway (scatter ER ER_hat_tA29c4, msize(vsmall)) (lfit ER ER_hat_tA29c4 if ER_hat_tA29c4>0),graphregion(color(white)) ytitle("Actual ER vote") xtitle("Fitted ER vote") title("Panel-tobit (Honoré 1992)") legend(off) saving(figureA2b,replace)
**Tobit-Dummies
tobit ER Lunemp Ldiff_immigration   Lgdp_pps_hab Ltax Lgini  Lwage_sh LD_gdp_growth    D_par  i.nuts_2,ll(0) 
predict ER_hat_tA29c5, xb
gen ER_resid_tA29c5=ER-ER_hat_tA29c5
twoway (scatter ER_resid_tA29c5 ER_hat_tA29c5, msize(vsmall)) , yline(0) graphregion(color(white)) ytitle("Residuals") xtitle("Fitted ER vote") title("Tobit - Regional dummies") legend(off) saving(figureA2c,replace)
twoway (scatter ER ER_hat_tA29c5, msize(vsmall)) (lfit ER ER_hat_tA29c5 if ER_hat_tA29c5>0),graphregion(color(white)) ytitle("Actual ER vote") xtitle("Fitted ER vote") title("Tobit - Regional dummies") legend(off) saving(figureA2d,replace)
*** Tobit random effects
xttobit ER Lunemp Ldiff_immigration   Lgdp_pps_hab Ltax Lgini  Lwage_sh LD_gdp_growth    D_par ,ll(0)
predict ER_hat_tA29c6, xb
gen ER_resid_tA29c6=ER-ER_hat_tA29c6
twoway (scatter ER_resid_tA29c6 ER_hat_tA29c6, msize(vsmall)) , yline(0) graphregion(color(white)) ytitle("Residuals") xtitle("Fitted ER vote") title("Random effects Tobit") legend(off)saving(figureA2e,replace)
twoway (scatter ER ER_hat_tA29c6, msize(vsmall)) (lfit ER ER_hat_tA29c6 if ER_hat_tA29c6>0,est(noconstant)),graphregion(color(white)) ytitle("Actual ER vote") xtitle("Fitted ER vote") title("Random effects Tobit") legend(off)saving(figureA2f,replace)
gr combine figureA2a.gph figureA2b.gph figureA2c.gph figureA2d.gph figureA2e.gph figureA2f.gph, graphregion(color(white)) rows(3) ysize(10) xsize(8)
graph save ../Graphs/FigureA2.gph, replace
graph export ../Graphs/FigureA2.pdf, replace

cd ..
